import {useState,useEffect} from "react";
import axios from "axios";

export function useCategoryList(){
    const [categoryList,setCategoryList] = useState([]);

    useEffect(()=>{
        axios({
            url:"http://121.89.205.189:3000/api/pro/categorylist"
        })
        .then(res=>{
            if(res.data.code==="200"){
                setCategoryList(res.data.data);
            }
        })
    },[])

    return categoryList;
}


// 获取商品的分页数据。
export function useProList(count=1,limitNum=10){
    const [proList,setProList] = useState([]);

    useEffect(()=>{
        axios({
            url:"http://121.89.205.189:3000/api/pro/list",
            params:{
                count,
                limitNum
            }
        })
        .then(res=>{
            if(res.data.code==="200"){
                setProList(res.data.data);
            }
        })
    },[count,limitNum])

    return proList;
}


export function useOnScroll(){
  useEffect(()=>{
    window.onscroll=function(){
        console.log("onscroll");
    }
  },[])
}